<%--
  Created by IntelliJ IDEA.
  User: Elle
  Date: 2022/3/7
  Time: 16:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="top">
    <div class="logo"><a href="client/Index.jsp"><img src="images/logo.png" /></a></div>
    <div class="search">
        <form>
            <input type="text" value="" class="s_ipt" />
            <input type="submit" value="搜索" class="s_btn" />
        </form>
        <span class="fl"><a href="#">咖啡</a><a href="#">iphone 6S</a><a href="#">新鲜美食</a><a href="#">蛋糕</a><a href="#">日用品</a><a href="#">连衣裙</a></span>
    </div>
    <div class="i_car">
        <div class="car_t">购物车 [ <span>${sessionScope.carList==null?0:sessionScope.carList.size()}</span> ]</div>
        <div class="car_bg">
            <!--Begin 购物车未登录 Begin-->
            <c:if test="${sessionScope.loginUser==null}">
            <div class="un_login">还未登录！<a href="Login.jsp" style="color:#ff4e00;">马上登录</a> 查看购物车！</div>
            </c:if>
            <!--End 购物车未登录 End-->
            <!--Begin 购物车已登录 Begin-->
            <ul class="cars">
                <c:forEach items="${sessionScope.carList}" var="carInfo">
                <li>
                    <div class="img"><a href="#"><img src="images/car1.jpg" width="58" height="58" /></a></div>
                    <div class="name"><a href="#">${carInfo.goods.goodsName} ${carInfo.goods.goodsDesc}</a></div>
                    <div class="price"><font color="#ff4e00">￥${carInfo.goods.price}</font> X${carInfo.count}</div>
                </li>
                 <c:set var="total" value="${total+(carInfo.goods.price*carInfo.count)}"/>
                </c:forEach>
            </ul>
            <div class="price_sum">共计&nbsp; <font color="#ff4e00">￥</font><span>${total}</span></div>
            <div class="price_a"><a href="client/buycar/BuyCar.jsp">去购物车结算</a></div>
            <!--End 购物车已登录 End-->
        </div>
    </div>
</div>

<script type="text/javascript">
    function addCar(goodsId) {
        $.ajax({
            url:"GoodsServlet?action=addCar&goodsId="+goodsId,
            dataType:"json",
            success:function(data){
                $.each(data,function(i,obj){
                    //清空
                    $(".cars").children().remove();
                    var tmp = "<li>\n" +
                        "                    <div class=\"img\"><a href=\"#\"><img src=\"images/car1.jpg\" width=\"58\" height=\"58\" /></a></div>\n" +
                        "                    <div class=\"name\"><a href=\"#\">"+obj.goods.goodsName+ obj.goods.goodsDesc+"</a></div>\n" +
                        "                    <div class=\"price\"><font color=\"#ff4e00\">￥"+obj.goods.price+"</font> X"+obj.count+"</div>\n" +
                        "                </li>";
                    //刷新购物车列表
                    $(".cars").append(tmp);
                });
                //购物车数量
                $(".car_t").find("span").text(data.length);
            }
        });
    }
</script>